package org.social.controller;

import java.util.List;
import java.util.stream.Collectors;
import org.social.db.bean.Dictionaries;
import org.social.db.cache.DictionariesCache;
import org.social.manager.DictionariesManager;
import com.dal.gm_api.api.IDictionary;

/**
 * 动态字典库
 * 
 * @author liu.jiang
 * @date 2018年4月10日
 */
public class DictionaryServer implements IDictionary {

    @Override
    public void addDictionary(String language, String contentKey, String contentVal) {
        DictionariesManager.putEntry(language, contentKey, contentVal);
    }

    @Override
    public void modifyDictionary(String language, String contentKey, String contentVal) {
        DictionariesManager.putEntry(language, contentKey, contentVal);
    }

    @Override
    public void deleteDictionary(List<Integer> ids) {
        DictionariesManager.remove(ids);
    }

    @Override
    public List<String> getAllDictionary() {
        List<Dictionaries> list = DictionariesCache.me().loadAll();
        return list.stream().map(dic -> dic.toJson()).collect(Collectors.toList());
    }

}
